<?php

namespace App\Validator\Admin\Rbac;

use App\Constants\Common\CommonCode;
use App\Validator\BaseValidator;
use Hyperf\Validation\Rule;

class ManagerValidator extends BaseValidator
{

    protected array $attr = [
        'id' => '账号ID',
        'account' => '登录账号',
        'nickname' => '昵称',
        'login_pwd' => '登录密码',
        'is_root' => '是否超级管理员',
        'role_ids' => '角色',
    ];

    public function pageList(array $data)
    {
        return $this->validatePage($data,[
            's_account' => ['nullable','string',],
            's_nickname' => ['nullable','string',],
            's_is_root' => ['nullable','integer',],
        ]);
    }

    public function add(array $data)
    {
        return $this->validate($data,[
            'account' => ['required','string',],
            'nickname' => ['required','string',],
            'login_pwd' => ['required','string','confirmed'],
            'is_root' => ['required','integer',Rule::in(CommonCode::validSwitch())],
            'role_ids' => ['nullable','array',],
            'role_ids.*' => ['integer',],
        ]);
    }

    public function update(array $data)
    {
        return $this->validate($data,[
            'id' => ['required','integer','min:1'],
            'is_root' => ['nullable','integer',Rule::in(CommonCode::validSwitch())],
            'nickname' => ['required','string',],
            'role_ids' => ['nullable','array',],
            'role_ids.*' => ['integer',],
        ]);
    }

    public function updateLoginPwd(array $data)
    {
        return $this->validate($data,[
            'id' => ['required','integer','min:1'],
            'login_pwd' => ['required','string','confirmed'],
        ]);
    }

    public function updateIsRoot(array $data)
    {
        return $this->validate($data,[
            'id' => ['required','integer','min:1'],
            'is_root' => ['required','integer',Rule::in(CommonCode::validSwitch())],
        ]);
    }

    public function del(array $data)
    {
        return $this->validate($data,[
            'ids' => ['required','array','min:1'],
            'ids.*' => ['required','integer','min:1'],
        ]);
    }

    public function detail(array $data)
    {
        return $this->validate($data,[
            'id' => ['required','integer','min:1'],
        ]);
    }

    public function updateSelfLoginPwd(array $data)
    {
        return $this->validate($data,[
            'login_pwd' => ['required','string','confirmed'],
        ]);
    }
}